<?
	/* Se asegura que el archivo es incluido por el index */
	defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
		$this->oTmpObject = new Accion_frm( $this );

	class Accion_frm extends Frm
	{
	function setValue ( $ncAccion)
		{
			$cSql = "SELECT cdAccion,cParametro,cIcono,cNombre,cObjetivo,ncTipoAccion,ncModo, ncSubModulo
				FROM stAccion
				WHERE ncAccion = $ncAccion";
			$aDatos = $this->oDatabase->getArray($cSql);
			$this->setFieldsArray ( $aDatos );
		}
	function Accion_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
			$this->aFields['ncAccion']      		= new Input( "Codigo", "ncAccion", '', false, true );
			$this->aFields['cdAccion']      		= new InputText( "Nombre",  "cdAccion" );
			$this->aFields['ncSubModulo']   	= new InputList ( "Submodulo",  "ncSubModulo" );
			$this->aFields['cParametro']    	= new InputText( "Parametro", "cParametro" );
			$this->aFields['cNombre']       		= new InputText( "Nombre", "cNombre" );
			//$this->aFields['cIcono']        		= new InputText( "Icono", "cIcono" );
			$this->aFields['cIcono']        		= new InputList( "Icono", "cIcono" );
			$this->aFields['ncTipoAccion']  	= new InputList ( "Tipo" , "ncTipoAccion" );
			$this->aFields['ncModo']        		= new InputList ( "Modo", "ncModo" );
			$this->aFields['cObjetivo']     		= new InputText ( "Objetivo", "cObjetivo" );
			$this->aFields['cPathModule']     = new InputText ( "Path", "cPathModule" );
			$cPathModule = getParam('cPathModule');
			$this->oDatabase = openMetadataDB ( $cPathModule );
		}
	function setLevel( $nLevel)
		{
			switch ( $nLevel )
			{
				case 2:
					$this->aInput = array ( 'ncAccion', 'cPathModule', 'cdAccion', 'ncSubModulo', 'cParametro', 'cIcono', 'ncTipoAccion','ncModo', 'cObjetivo' );
					break;
				case 3:
					$this->aInput = array ( 'ncAccion', 'cdAccion', 'ncSubModulo' );
					$cSql = "SELECT ncClase, cArchivo FROM stClase";
					$aMatrixClases = $this->oDatabase->getMatrix($cSql);
					$aClases = $this->oDatabase->getMatrix( "SELECT * FROM stAccionClase WHERE ncAccion = ". $this->aFields['ncAccion']->getValue() . 'ORDER BY ncOrden'  );
					foreach( $aClases  as $aClase )
					{
						$cField = 'ncClase_' . $aClase['ncOrden'];
						$this->aFields[$cField] = new InputList ( 'Clase ' . $aClase['ncOrden']  . ' (' . $aClase['cMetodo'] . ')', $cField );
						$this->aInput[] = $cField;
						$this->aFields[$cField]->setMatrix( $aMatrixClases );
						$this->aFields[$cField]->setValue( $aClase['ncClase'] );
						$this->aFields[$cField]->addActionArray( 2, $this->oModule->getActionArray( AGREGAR_CLASE ), "ncClase=" . $aClase['ncClase']);
					}
					$this->aFields['ncAccionPermiso'] = new InputList ( '', 'ncAccionPermiso', $this->aFields['ncAccion']->getValue()  );
					$this->aInput[] = 'ncAccionPermiso';
					$this->aFields['ncAccionPermiso']->setForm( $this );
					initializeAccion( $this->aFields['ncAccionPermiso'], 'ncAccionPermiso' );
					break;
			}
		}
	function initializeForm()
		{
			// Si viene el Ubicacion hace el retrieve
				$ncAccion = $this->aFields['ncAccion']->getValue() ;
				if ( getParam('ncAccionPermiso')) $ncAccion =  getParam('ncAccionPermiso');
				if ( $this->isRetrievable() && $ncAccion  )
				{
					$this->setValue( $ncAccion );
				}
			// Configura el Titulo
				$this->setLabel( "Accion" );
			return true;
		}
	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
				case 'cPathModule':
					$oField->setHidden();
				break;
				case 'cdAccion':
					$oField->setLength( 100 );
				break;
				case 'ncSubModulo':
					$cSql = "select ncSubModulo, cdSubModulo from stSubModulo";
					$oField->setForm($this);
					$oField->setMandatory();
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql) );
					$oField->addActionArray ( 2, $this->oModule->getActionArray( AGREGAR_UN_SUBMODULO ) );
				break;
				case 'cParametro':
					$oField->setLength( 120 );
				break;
				case 'cNombre':
					$oField->setLength( 40 );
				break;
				case 'cIcono':
					//$oField->setLength( 20 );
					$oField->setDirectory( PATH_MODULES . 'base/images' );
				break;
				case 'ncModo':
					$cSql = "select ncModo, cdModo from scModo";
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql) );
					$oField->setDefault( 1 );
				break;
				case 'ncTipoAccion':
					$cSql = "SELECT ncTipoAccion, cdTipoAccion FROM scTipoAccion";
					$oField->setMatrix( $this->oDatabase->getMatrix($cSql) );
					$oField->setDefault( 3 );
					//$oField->setValue( 3 );
				break;
				case 'cObjetivo':
					$oField->setLength( 250 );
					$oField->setEditor();
				break;
			}
 		}
	}
?>
